import { observable, action, computed } from 'mobx'
import { request } from '../utils/axios'
import store from 'store'
import {baseConfig} from '../utils/constants'

export default class MenuState {
  @observable menus;
  @observable navpath;
  @observable menuMainKey;

  constructor() {
    this.menus = []
    this.navpath = []
    this.menuMainKey = null;
  }


  /**
   * ******************************http request******************************
   * */

  async getUserMenus() {

    const {data} = await request(
      {
        method: 'get',
        url: '/api/sysMenu/user',
        params: {
          token: store.get(baseConfig.store.USER_TOKEN)
        },
      }
    );

    this.setUserMenus(data.data)
    return Promise.resolve(data.data)
  }

  setMenuMainInx(menuMainIndex){
    this.setMenuMainKey(menuMainIndex);
  }

  /**
   * ******************************action******************************
   * */

  @action
  setUserMenus(data) {
    this.menus = data
  }

  @action
  setMenuMainKey(menuMainKey) {
    this.menuMainKey = menuMainKey
  }
}
